package com.wxhntmy.config;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.yaml.snakeyaml.Yaml;

/**
 * 项目配置
 *
 * @author chenwc
 * @package com.wxhntmy
 * @project GoogleTranslate
 * @date 2025/6/23
 */
public class ProjectConfig {
    private static final Logger logger = LoggerFactory.getLogger(ProjectConfig.class);
    /**
     * 是否使用json文件私钥
     */
    private boolean useJsonPrivateKey = true;
    /**
     * 是否使用代理
     */
    private boolean useProxy = true;
    /**
     * redis配置
     */
    private RedisConfig redis;
    /**
     * http代理配置
     */
    private HttpProxyConfig http;
    /**
     * google配置
     */
    private Google google;

    private static ProjectConfig instance;

    public static ProjectConfig getInstance() {
        if (null == instance){
            try {
                // 安全解析模式
                Yaml yaml = new Yaml();
                return yaml.loadAs(ProjectConfig.class.getResourceAsStream("/config.yaml"),
                        ProjectConfig.class);
            } catch (Exception e) {
                logger.error("Error occurred: ", e);
            }
        }
        return instance;
    }

    public boolean isUseProxy() {
        return useProxy;
    }

    public void setUseProxy(boolean useProxy) {
        this.useProxy = useProxy;
    }

    public boolean isUseJsonPrivateKey() {
        return useJsonPrivateKey;
    }

    public void setUseJsonPrivateKey(boolean useJsonPrivateKey) {
        this.useJsonPrivateKey = useJsonPrivateKey;
    }

    public RedisConfig getRedis() {
        return redis;
    }

    public void setRedis(RedisConfig redis) {
        this.redis = redis;
    }

    public HttpProxyConfig getHttp() {
        return http;
    }

    public void setHttp(HttpProxyConfig http) {
        this.http = http;
    }

    public Google getGoogle() {
        return google;
    }

    public void setGoogle(Google google) {
        this.google = google;
    }
}
